home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Software Contest 3 / FM Towns Software Contest 3.iso / exp / astral / a1 / game / source / asmsub.asm < prev    next >
Assembly Source File  |  1994-01-07  |  8KB  |  418 lines

  1. ;*******************************************************************
  2. ;***                                                             ***
  3. ;***    ワイヤーフレームプログラム用 アセンブラサブルーチン群    ***
  4. ;***                                                             ***
  5. ;*******************************************************************
  6.  
  7. .386p
  8.  
  9. ;============================================================================
  10. ;    シンボル設定
  11. ;============================================================================
  12.  
  13. CRTC_addr_reg    equ    0440h        ;CRTC
  14. CRTC_data_reg    equ    0442h
  15.  
  16. VSYNC_clear_reg    equ    05cah        ;VSYNC割り込み要因クリアレジスタ
  17.  
  18. PIC_ocw1m    equ    0002h        ;PIC
  19. PIC_ocw1s    equ    0012h
  20. PIC_ocw2m    equ    0000h
  21. PIC_ocw2s    equ    0010h
  22. PIC_ocw3m    equ    0000h
  23. PIC_ocw3s    equ    0010h
  24. PIC_isrm    equ    0000h
  25. PIC_isrs    equ    0010h
  26.  
  27. CRTC_reg    equ    0440h
  28.  
  29. PAD1_in        equ    04d0h
  30. PAD2_in        equ    04d2h
  31. PAD_out        equ    04d6h
  32.  
  33. VRAM_seg    equ    0120h        ;VRAM(2画面モード)セレクタ
  34.  
  35. int_VSYNC    equ    000bh        ;VSYNCの割り込み番号
  36.  
  37. clear_color    equ    6        ;画面消去で塗り潰す色
  38.  
  39. DOSX_nv_get    equ    2502h        ;DOS-Extenderのファンクション
  40. DOSX_rv_get    equ    2503h
  41. DOSX_nv_set    equ    2504h
  42. DOSX_rv_set    equ    2505h
  43. DOSX_r2nv_set    equ    2506h
  44. DOSX_rnv_set    equ    2507h
  45. DOSX_hdv_get    equ    250ch
  46.  
  47. ;============================================================================
  48. ;    データ領域
  49. ;============================================================================
  50.  
  51.  
  52. DSEG    segment    dword    public    'DATA'
  53.  
  54. n_vect_seg    dw    0        ;Nativeベクタ保存領域
  55. n_vect_off    dd    0
  56. r_vect        dd    0        ;Realベクタ保存領域
  57. handler_main    dd    0        ;割り込みハンドラのエントリ
  58. ocw1m_buf    db    0        ;PICのレジスタ保存領域
  59. ocw1s_buf    db    0
  60. int_flag    dd    0        ;多重割り込み防止用フラグ
  61. Vbuf        dd    6 dup(?)
  62.  
  63. DSEG    ends
  64.  
  65. ;============================================================================
  66. ;    コード領域
  67. ;============================================================================
  68.  
  69. CSEG    segment    dword    public    'CODE'
  70.     assume    cs:CSEG,ds:DSEG
  71.  
  72. ;----------------------------------------------------------------------------
  73. ;    int VSYNC_set(void (*entry)(void))
  74. ;     VSYNCの割り込みハンドラを登録する関数.
  75. ;      この関数はかなり893(Ya・Ku・Za)だなぁ.
  76. ;      ERiCON,ARiCONなんかから立ち上げると暴走するよ.
  77. ;      Towns-OS V2.1コンソールだとまともに動くけどネ.
  78. ;----------------------------------------------------------------------------
  79.  
  80.     public    VSYNC_set
  81.  
  82.     db    'VSYNC_set',9
  83.  
  84. VSYNC_set    proc    near
  85.  
  86.     push    ebp
  87.     mov    ebp,esp
  88.     push    edi
  89.     push    esi
  90.     push    ebx
  91.     push    ds
  92.     push    es
  93.  
  94.     mov    eax,ss:[ebp]+4+4
  95.     mov    handler_main,eax
  96.  
  97.     mov    ax,DOSX_hdv_get        ;VSYNC割り込みのベースを求める
  98.     int    21h
  99.     jb    error
  100.     mov    cl,ah
  101.     add    cl,int_VSYNC-8
  102.  
  103.     mov    ax,DOSX_nv_get        ;Nativeモードの割り込みベクトルを保存
  104.     int    21h
  105.     jb    error
  106.     mov    ax,es
  107.     mov    n_vect_seg,ax
  108.     mov    n_vect_off,ebx
  109.  
  110.     mov    ax,DOSX_rv_get        ;Realモードの割り込みベクトルを保存
  111.     int    21h
  112.     jb    error
  113.     mov    r_vect,ebx
  114.  
  115.     mov    ax,DOSX_r2nv_set    ;新しく割り込みベクトルをセット
  116.     push    ds
  117.     push    cs
  118.     pop    ds
  119.     mov    edx,offset handler
  120.     int    21h
  121.     jb    error
  122.  
  123.     pop    ds
  124.  
  125.     in    al,PIC_ocw1s        ;VSYNC割り込みを許可&他の割り込みを禁止
  126.     mov    ocw1s_buf,al
  127.     and    al,11110111b
  128.     out    PIC_ocw1s,al
  129.  
  130.     pop    es
  131.     pop    ds
  132.     pop    ebx
  133.     pop    esi
  134.     pop    edi
  135.     pop    ebp
  136.     mov    eax,0
  137.     
  138.     ret
  139.  
  140. error:
  141.     pop    es
  142.     pop    ds
  143.     pop    ebx
  144.     pop    esi
  145.     pop    edi
  146.     pop    ebp
  147.     mov    eax,1
  148.  
  149.     ret
  150.  
  151. VSYNC_set    endp
  152.  
  153. ;----------------------------------------------------------------------------
  154. ;    割り込みハンドラの本体
  155. ;----------------------------------------------------------------------------
  156.  
  157. handler:
  158.     push    ds
  159.     push    es
  160.     push    fs
  161.     push    gs
  162.     pushad
  163.  
  164.     mov    dx,VSYNC_clear_reg    ;VSYNC割り込み要因をクリア
  165.     out    dx,al
  166.  
  167.     call    handler_main        ;割り込みハンドラを呼出し
  168.  
  169.     mov    al,00100000b        ;EOIを発行
  170.     out    PIC_ocw2s,al
  171.     mov    al,00001011b
  172.     out    PIC_ocw3s,al
  173.     in    al,PIC_isrs
  174.     cmp    al,0
  175.     jnz    pass_eoi
  176.     mov    al,00100000b
  177.     out    PIC_ocw2m,al
  178.  
  179. pass_eoi:
  180.     popad
  181.     pop    gs
  182.     pop    fs
  183.     pop    es
  184.     pop    ds
  185.  
  186. exit_handler:
  187.     iretd
  188.  
  189. ;----------------------------------------------------------------------------
  190. ;    void VSYNC_end(int dummy)
  191. ;     VSYNC割り込みベクトルを元に戻す関数.
  192. ;      ERiCON,ARiCONなんかだとこれを実行しても無駄だよ~ん.
  193. ;----------------------------------------------------------------------------
  194.  
  195.     public    VSYNC_end
  196.  
  197.     db    'VSYNC_end',9
  198.  
  199. VSYNC_end    proc    near
  200.  
  201.     push    ebp
  202.     push    edi
  203.     push    esi
  204.     push    ebx
  205.     push    ds
  206.     push    es
  207.  
  208.     mov    al,ocw1s_buf        ;VSYNC割り込みマスクを元に戻す
  209.     out    PIC_ocw1s,al
  210. ;    mov    al,ocw1m_buf
  211. ;    out    PIC_ocw1m,al
  212.  
  213.     mov    ax,DOSX_hdv_get        ;VSYNC割り込みのベースを求める
  214.     int    21h
  215.     mov    cl,ah
  216.     add    cl,int_VSYNC-8
  217.  
  218.     mov    ax,DOSX_rnv_set        ;割り込みベクトルを元に戻す
  219.     mov    bx,n_vect_seg
  220.     mov    ds,bx
  221.     mov    edx,n_vect_off
  222.     mov    ebx,r_vect
  223.     int    21h
  224.  
  225. exit2:
  226.  
  227.     pop    es
  228.     pop    ds
  229.     pop    ebx
  230.     pop    esi
  231.     pop    edi
  232.     pop    ebp
  233.  
  234.     ret
  235.  
  236. VSYNC_end    endp
  237.  
  238. ;----------------------------------------------------------------------------
  239. ;    int SND_init2(char *work)
  240. ;----------------------------------------------------------------------------
  241.  
  242.     public    SND_init2
  243.     db    'SND_init2',9
  244.  
  245. SND_init2    proc    near
  246.     push    edi
  247.     push    esi
  248.     push    gs
  249.     push    fs
  250.  
  251.     mov    edi,ss:[esp]+16+4
  252.     mov    ax,110h
  253.     mov    fs,ax
  254.     mov    ah,00h
  255.     call    pword ptr fs:80h
  256.  
  257.     pop    fs
  258.     pop    gs
  259.     pop    esi
  260.     pop    edi
  261.  
  262.     ret
  263.  
  264. SND_init2    endp
  265.  
  266. snd_entry    proc    far
  267.     push    edx
  268.     push    eax
  269.     push    fs
  270.     
  271.     mov    dx,04e9h
  272.     in    al,dx
  273.     and    al,00001000b
  274.     jz    snd_exit
  275.     mov    ax,110h
  276.     mov    fs,ax
  277.     mov    ah,51h
  278.     call    pword ptr fs:80h
  279.  
  280. snd_exit:
  281.     pop    fs
  282.     pop    eax
  283.     pop    edx
  284.  
  285.     ret
  286.  
  287. snd_entry    endp
  288.  
  289.  
  290. ;----------------------------------------------------------------------------
  291. ;    void CRTC_out(int addr,int num)
  292. ;     CRTCのレジスタ書き込み
  293. ;----------------------------------------------------------------------------
  294.  
  295.     public CRTC_out
  296.     
  297.     db    'CRTC_out',8
  298.  
  299. CRTC_out    proc    near
  300.     mov    dx,CRTC_reg
  301.     mov    al,ss:[esp]+4
  302.     out    dx,al
  303.     add    dx,2
  304.     mov    ax,ss:[esp]+8
  305.     out    dx,ax
  306.     ret
  307.  
  308. CRTC_out    endp
  309.  
  310. ;----------------------------------------------------------------------------
  311. ;    int pad_in(void);
  312. ;     パッドを読み出す(SND_joy_in_1相当)
  313. ;----------------------------------------------------------------------------
  314.  
  315.     public    pad_in
  316.  
  317.     db    "pad_in",6
  318.  
  319. pad_in        proc    near
  320.  
  321.     mov    dx,PAD_out
  322.     mov    al,00101111b
  323.     out    dx,al
  324.  
  325.     mov    eax,0
  326.     mov    dx,PAD1_in
  327.     in    al,dx
  328.  
  329.     ret
  330.  
  331. pad_in        endp
  332.  
  333. ;----------------------------------------------------------------------------
  334. ;    void cls(int page,int color)
  335. ;     画面消去の関数
  336. ;----------------------------------------------------------------------------
  337.  
  338.     public    clear_screen
  339.  
  340.     db    'clear_screen',12
  341.  
  342. clear_screen    proc    near
  343.  
  344.     push    esi
  345.     push    edi
  346.     push    es
  347.  
  348.     mov    edi,ss:[esp]+12+4
  349.     shl    edi,17
  350.  
  351.     mov    ax,VRAM_seg
  352.     mov    es,ax
  353.     mov    ecx,256*256*2/4
  354.     mov    eax,ss:[esp]+12+8
  355.     shl    eax,16
  356.     add    eax,ss:[esp]+12+8
  357.     rep    stosd
  358.  
  359.     pop    es
  360.     pop    edi
  361.     pop    esi
  362.  
  363.     ret
  364.  
  365. clear_screen    endp
  366.  
  367. ;----------------------------------------------------------------------------
  368. ;    void wait_VSYNC(void)
  369. ;     VSYNCを待つ関数
  370. ;----------------------------------------------------------------------------
  371.  
  372.     public    wait_VSYNC
  373.  
  374.     db    'wait_VSYNC',10
  375.  
  376. wait_VSYNC    proc    near
  377.  
  378. loop1:
  379.     mov    dx,CRTC_addr_reg
  380.     mov    al,30
  381.     out    dx,al
  382.     inc    dx
  383.     inc    dx
  384.     in    ax,dx
  385.     and    ax,0000010000000000b
  386.     jz    loop1
  387.  
  388.     ret
  389.  
  390. wait_VSYNC    endp
  391.  
  392. ;----------------------------------------------------------------------------
  393. ;    void chgpage(int page);
  394. ;     表示ページを切り換える関数
  395. ;----------------------------------------------------------------------------
  396.  
  397.     public    chgpage
  398.  
  399.     db    'chgpage',7
  400.  
  401. chgpage        proc    near
  402.  
  403.     mov    dx,CRTC_addr_reg
  404.     mov    al,17
  405.     out    dx,al
  406.     inc    dx
  407.     inc    dx
  408.     mov    ax,ss:[esp]+4
  409.     shl    ax,15
  410.     out    dx,ax
  411.     ret
  412.  
  413. chgpage        endp
  414.  
  415. CSEG    ends
  416.  
  417.     end
  418.